/*  Mash-code. Mash Arts & Métiers Angers embedded software
 *  Copyright (C) 2014  Mash Arts & Métiers Angers
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "configure.h"
 
/***********************/
/* Pin Configuration   */
/***********************/

_FPOR(ALTI2C_OFF & LPOL_ON & HPOL_ON & PWMPIN_ON & FPWRT_PWR1);
_FICD(JTAGEN_OFF & ICS_PGD3)

void initPin()
{
	/* Configuration Pin ADC */
	AD1PCFGL = 0b00011111;
	
	/* Configuration PORT A */
	TRISA = 0b0000000000000000;
	
	/* Configuration PORT B */
	TRISB = 0b0000000000011100;
	
	return 0;
}

/****************************/
/* Oscillator Configuration */
/****************************/

void initOscillator()
{
	/*The Fast RC (FRC) internal oscillator runs at a nominal frequency of 7.37 MHz. */
	OSCCONbits.NOSC = 001;

	/*
	N1 (PPLPRE)  = 2
	N2 (PLLPOST) = 4
	M  (PPLDIV)  = 85
	
	Fosc = 78.306 MHz
	Fcy = 39.153 MHz
	*/
	CLKDIVbits.PPLPOST=0b01;
	CLKDIVbits.PPLPRE=0b0000;
	CLKDIVbits.PPLDIV=84;
}